package cn.zzp.pet.service.impl;

import cn.zzp.basic.service.impl.BaseServiceImpl;
import cn.zzp.pet.domain.Pet;
import cn.zzp.pet.domain.PetDetail;
import cn.zzp.pet.mapper.PetMapper;
import cn.zzp.pet.mapper.PetDetailMapper;
import cn.zzp.pet.service.PetService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


/**
 * @ClassName
 * @Description
 * @Author 祝志鹏
 * @Date 2022/7/14 14:16
 */
@Service
//@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class PetServiceImpl extends BaseServiceImpl<Pet> implements PetService {

    @Autowired
    private PetMapper petMapper;
    @Autowired
    private PetDetailMapper petDetailMapper;

    /**
     * 添加操作
     * @param pet
     */
    @Transactional
    @Override
    public void add(Pet pet) {
        petMapper.add(pet);

        PetDetail petDetail = pet.getPetDetail();
        petDetail.setPet_id(pet.getId());

        petDetailMapper.add(petDetail);
    }

    /**
     * 更新操作
     * @param pet
     */
    @Transactional
    @Override
    public void update(Pet pet) {

        petMapper.update(pet);

        petDetailMapper.update(pet.getPetDetail());

    }

    /**
     * 删除操作
     * @param id
     */
    @Transactional
    @Override
    public void delete(Long id) {
        petMapper.delete(id);
        petDetailMapper.deleteByPetId(id);
    }

    /**
     * 上架
     * @param ids
     */
    @Transactional
    @Override
    public void onsale(List<Long> ids) {
        Date date = new Date();
        petMapper.onSale(ids,date);
    }

    /**
     * 下架
     * @param ids
     */
    @Transactional
    @Override
    public void offsale(List<Long> ids) {
        Date date = new Date();
        petMapper.offSale(ids,date);
    }
}
